package com.youth.service;

import com.youth.entity.po.Area;
import com.youth.mapper.IAreaMapper;
import com.youth.result.ResultBean;
import com.youth.result.StatusEnum;
import com.youth.service.vo.IAreaVOService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @ClassName AreaService
 * @Description: TODO
 * @Author yjwu
 * @Date 2019/10/21 22:22
 **/
@Service
public class AreaService {
    @Autowired
    private IAreaMapper areaMapper;

    public ResultBean add(Area area) {
        ResultBean resultBean = null;
        try {
            resultBean = ResultBean.returnDeleteSuccess(areaMapper.add(area));
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException();
        } finally {
            return resultBean;
        }
    }

    public ResultBean deleteById(int id) {
        ResultBean resultBean = null;
        try {
            resultBean = ResultBean.returnDeleteSuccess(areaMapper.deleteById(id, StatusEnum.NOTINUSE.getStatus(), new Date()));
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException();
        } finally {
            return resultBean;
        }
    }

    public ResultBean updateById(Area area) {
        ResultBean resultBean = null;
        try {
            resultBean = ResultBean.returnDeleteSuccess(areaMapper.updateById(area));
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException();
        } finally {
            return resultBean;
        }
    }

    public ResultBean findById(int id) {
        ResultBean resultBean = null;
        try {
            resultBean = ResultBean.returnDeleteSuccess(areaMapper.findById(id));
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException();
        } finally {
            return resultBean;
        }
    }

    public ResultBean findAllByStatus(int status) {
        ResultBean resultBean = null;
        try {
            resultBean = ResultBean.returnDeleteSuccess(areaMapper.findAllByStatus(status));
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException();
        } finally {
            return resultBean;
        }
    }
}
